/**
 * 好友排行榜
 */
class RankUI extends UIBase{

    private mainGp:eui.Group;
    private rankGp:eui.Group;

    private btn_left:BaseButton;
    private btn_right:BaseButton;

    private curPage:number;
    private btn_back:BaseButton;

    constructor(data?)
    {
        super('RankView')
    }

    public init()
    {
        this.curPage = 0;
        this.width = GlobalManager.instance().curWidth();
        this.height = GlobalManager.instance().curHeight();
        // RankManager.instance().updateFriendCloudStorage();
        this.btn_left.visible = false;
        this.getRank();
    }

    protected addEvent()
    {
        super.addEvent();
        this.btn_left.addTapHandler(this.LeftBtnOnClick, this);
        this.btn_right.addTapHandler(this.RightBtnOnClick, this);
        this.btn_back.addTapHandler(this.backHandle, this);
    }

    public backHandle()
    {
        RankManager.instance().closeFriendCloudStorage();
        this.remove(1);
    }

    protected LeftBtnOnClick()
    {
        if(this.curPage <= 0)
        {
            MessageUtil.tips("到了最前面了哦");
            return;
        }
        this.curPage --;
        if(this.curPage <= 0)
        {
            this.btn_left.visible = false;
        }
        RankManager.instance().requestLastPageData();
    }

    protected RightBtnOnClick()
    {
        this.curPage ++;
        this.btn_left.visible = true;
        RankManager.instance().requestNextPageData();
    }

    public getRank()
    {
        let bitmap_rank = WeChatgGameManager.instance().createRankListDisplayObject();
        if(bitmap_rank)
        this.rankGp.addChild(bitmap_rank);
    }

    protected removeEvent()
    {
        super.removeEvent();
        this.btn_left.removeTapHandler();
        this.btn_right.removeTapHandler();
        this.btn_back.removeTapHandler();
    }

    public clear()
    {
        super.clear();
        this.curPage = null;
    }
}